package com.yt.calendar.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yt.calendar.entity.Config;
import com.yt.calendar.mapper.ConfigMapper;
import com.yt.calendar.service.IConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 系统配置表 服务实现类
 * </p>
 *
 * @author yt
 * @since 2021-07-16
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config> implements IConfigService {
    @Resource
    private ConfigMapper configMapper;

    @Override
    public Config getOneByAppAndTypeAndCodeAndParent(String appId, String type, String code, String parentId) {
        QueryWrapper<Config> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("app_id", appId).eq("type", type).eq("code", code).eq("parent_id", parentId);
        return this.getOne(queryWrapper);
    }

    @Override
    public void updateOneByAppAndTypeAndCodeAndParent(String appId, String type, String code, String parentId, String value) {
        UpdateWrapper<Config> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("value", value);
        updateWrapper.eq("app_id", appId).eq("type", type).eq("code", code).eq("parent_id", parentId);
        this.update(updateWrapper);
    }
}
